/**
 * @class   wosh::gui::KioskSecurity
 * @brief   
 *
 *
 ****************************************************************************
 * @version $Id: KioskSecurity.h 2887 2010-08-11 08:09:41Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Gui_KioskSecurity_H__
 #define __WOSH_Gui_KioskSecurity_H__

#include <QtCore>
#include <QtGui>

#include <QtGui/QGraphicsRectItem>
#include <QtGui/QTabWidget>

#include <framework/gui/IWidget.h>
#include <framework/gui/GuiUtilities.h>
//#include <framework/security/SecurityAuthenticationPassWord.h>

#include <core/UserManager.h>
#include "KioskDialogLogin.h"


namespace wosh {
 namespace gui {


class KioskSecurity : public QObject {

	Q_OBJECT

	public:
		KioskSecurity( QObject* parent = NULL ) : QObject(parent) {
			this->loginLogged = false;
			this->loginTs = 0;

			this->dialogLogin = new KioskDialogLogin();
			connect(this->dialogLogin, SIGNAL(login_request(const QString&, const QString&)), this, SLOT(check_login(const QString&, const QString&)));
			connect(this->dialogLogin, SIGNAL(system_dialog_request()), this, SLOT(request_system_dialog()));
		 }
		virtual ~KioskSecurity() {
			delete this->dialogLogin;
		}

	public slots:

	protected slots:
		void check_login( const QString& username, const QString& password ) {
			(void)password;
			string user = username.toLatin1().data();
			bool auth = false;//UserManager::isAuthorized( user, password.toLatin1().data() );
			//::setUser( user, new wosh::security::SecurityTokenProviderPassWord() );
			if ( auth ) {
				emit userLoggedIn();
				return;
			 }
			else {
				emit userAuthorizationFault();
				this->dialogLogin->denied("Login error");
			 }
		 }
		void request_system_dialog() {
		 }


	signals:
		void userLoggedIn();
	//	void userLoggedOut();
		void userAuthorizationFault();


	public:
		KioskDialogLogin* getDialogLogin() { return this->dialogLogin; }

	protected:
		bool loginLogged;
		long loginTs;

		KioskDialogLogin* dialogLogin;


}; // class def

  }; // namespace gui
}; // namespace wosh

#endif //__WOSH_Gui_KioskSecurity_H__
